const express = require("express");

const mysql = require("mysql");

const app = express();

app.listen(3000,()=>{
    console.log("3000端口已打开");
})
const STUINFO = "stuinfo"
let mysqlcon = mysql.createConnection({host:"127.0.0.1",port:"3306",user:"root",password:"root",database:"mydb"});

let getdata = `select * from ${STUINFO}`;


function toquery()
{
    return new Promise((resolve,reject)=>{

        mysqlcon.connect();
        
        mysqlcon.query(getdata,(err,data)=>{
           
            if(err)
            {
               resolve([false,err]); 
            }
            else
            {
                resolve([true,data]);
            }
            
     })

    })
}
app.use("/",(req,res)=>{ 
    async function todisplaydata()
    {
      let [flag,data]  = await toquery();

      if(flag)
      {
          res.send(data);
      }
      else
      {
          res.send(`信息获取失败${data}`);
      }
    }
    todisplaydata()
})